package com.siki.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.siki.Utils.SystemMsgJsonResponse;
import com.siki.entity.bigdata.Chess;
import com.siki.mapper.ChessMapper;
import com.siki.vo.ChessVO;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Queue;
import java.util.stream.Collectors;

/**
 * @author Siki
 * @date 2020/12/22
 */
@RestController
@RequestMapping("/bigdata")
@CrossOrigin
public class BigDataController {

    private final ChessMapper chessMapper;

    public BigDataController(ChessMapper chessMapper) {
        this.chessMapper = chessMapper;
    }

    @PostMapping("/move")
    @ApiOperation(value = "判断走棋接口",httpMethod = "POST",consumes = "application/form-data")
    public SystemMsgJsonResponse move(String init) {
        List<ChessVO> count = chessMapper.findMoveInBlackWinByInit(init)
                .stream().map(ChessVO::new).collect(Collectors.toList());
        if (count.size() == 0) {
            count = chessMapper.findMoveInDrawByInit(init)
                    .stream().map(ChessVO::new).collect(Collectors.toList());
        }
        return SystemMsgJsonResponse.success(count);
    }

    @PostMapping("/learn")
    @ApiOperation(value = "学习走棋接口",httpMethod = "POST",consumes = "application/form-data")
    public SystemMsgJsonResponse learn(String init,
                                       String moveInit) {
        Chess chess = new Chess();
        chess.setInit(init).setMoveInit(moveInit).setCount("1");
        chessMapper.insertMoveInitIntoBlackWin(chess);
        return SystemMsgJsonResponse.success();
    }
}
